package org.hugh.space.filter;

import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.hugh.space.business.Business;
import org.hugh.space.dao.Dao;
import org.springframework.web.context.support.WebApplicationContextUtils;

public abstract class AbstractFilter {
	
	private FilterConfig config;
	private ServletContext servletContext;

	private Dao dao;
	private Business business;
	

	public AbstractFilter() {
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		config = filterConfig;
		servletContext = config.getServletContext();
		dao = (Dao) getSpringBean("dao");
		business = (Business) getSpringBean("business");
	}
	
	public void destroy() {
	}
	
	protected Object getSpringBean(final String name) {
		return WebApplicationContextUtils.getRequiredWebApplicationContext(
				servletContext).getBean(name);
	}
	
	public Dao getDao() {
		return dao;
	}
	
	public Business getBusiness() {
		return business;
	}

}
